import 'package:flutter/material.dart';

class ListViewApp extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState

    return new ListViewState();
  }
}

class ListViewState extends State<ListViewApp> {
  List<ListItem> listData = [];

  @override
  void initState() {
    super.initState();
    for (int i = 0; i < 100; i++) {
      listData.add(
          new ListItem("我是测试数据$i", i % 2 > 0 ? Icons.cake : Icons.ac_unit));
    }
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build

    return new Scaffold(
      appBar: new AppBar(
        title: new Text("ListView"),
      ),
      body: new ListView.builder(
        itemBuilder: (BuildContext context, int index) {
          return new ListItemWidget(listData[index]);
        },
        itemCount: listData.length,
      ),
    );
  }
}

class ListItem {
  String title;
  IconData iconData;

  ListItem(this.title, this.iconData);
}

class ListItemWidget extends StatelessWidget {
  ListItem listItem;

  ListItemWidget(this.listItem);

  @override
  Widget build(BuildContext context) {
    // TODO: implement build

    return new ListTile(
        leading: new Icon(listItem.iconData), title: new Text(listItem.title));
  }
}
